import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * class for get database connection
 * @author Miao Jiang
 *
 */
public class DatabaseConnector {

	private static Connection conn = null;
	
	public static Connection getConnection(){
		if(conn == null){
			try {
				Class.forName("com.mysql.jdbc.Driver");
				String url = "jdbc:mysql://ist402.ist.psu.edu/nks125";
				conn = DriverManager.getConnection(url, "nks125", "qwert123y");
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				conn = null;
			} catch (SQLException e) {
				e.printStackTrace();
				conn = null;
			}
		}
		
		return conn;
	}
	
	public boolean closeConnection(){
		if(conn != null){
			try {
				conn.close();
				conn = null;
				return true;
			} catch (SQLException e) {
				e.printStackTrace();			
			}
		}
		return false;
	}

}
